package com.topscore.uke.mvp.model;

import com.topscore.uke.entities.MemberBodyData;
import com.topscore.uke.mvp.contractors.GetMemberBodyDataContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/10/20.
 */

public class GetMemberBodyDataModel implements GetMemberBodyDataContractor,GetMemberBodyDataContractor.Model{

    private Listener mListener;

    public GetMemberBodyDataModel(Listener listener) {
        this.mListener = listener;
    }

    @Override
    public void getData(String phone) {
        mService.getBodyData(phone)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<MemberBodyData>>(mListener) {
                    @Override
                    public void onSuccess(BaseResponse<MemberBodyData> response) {
                        mListener.onGetDataSuccess(response.getData());
                    }
                });
    }
}
